﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;

/// <summary>
/// Summary description for OrderBus
/// </summary>
public class OrderBus
{
    orderDAL orDAL;
	public OrderBus()
	{
        orDAL = new orderDAL();
	}
    public bool addOrder(order order)
    {
        bool f=false;
        orderDAL orderDAL=new orderDAL();
        if(orderDAL.addOrder(order)!=0){
            f = true;
        }else{
            f = false;
        }
        return f;
    }
    public bool addOrderProduct(order_product order_product)
    {
        bool f = false;
        orderDAL orderDAL = new orderDAL();
        if (orderDAL.addOrderProduct(order_product) != 0)
        {
            f = true;
        }
        else
        {
            f = false;
        }
        return f;
    }
    public int getOrderID(int customer_id)
    {
        orderDAL orderDAL = new orderDAL();
        DataTable dt = new DataTable();
        dt = orderDAL.getOrderByDateAdded(customer_id);
        DataRow dr = dt.Rows[0];
        if(!dr.HasErrors){
            return Convert.ToInt32(dr["order_id"].ToString());
        }else{
            return 0;
        }
    }

    public DataTable getOrderByCustomerID(int customer_id)
    {
        
        DataTable dt = new DataTable();
        dt = orDAL.getOrderbyCustomer_id(customer_id);
        return dt;


        
    }

    public string getOrderStatusName(int order_id){
        orderDAL orderDAL = new orderDAL();
        DataTable dt = new DataTable();
        dt = orderDAL.getOrderByOrderID(order_id);
        DataRow dr = dt.Rows[0];
        if (!dr.HasErrors)
        {
            return dr["name"].ToString();
        }
        else
        {
            return null;
        }
    }
    public DataTable getOrderProductByOrder_id(int order_id)
    {
        orderDAL orderDAL = new orderDAL();
        DataTable dt = new DataTable();
        dt = orderDAL.getOrderProducbyOrder_id(order_id);
        return dt;
    }
    public void UpdateProductOrder(int product_id){
        productDAL proDAL = new productDAL();
        proDAL.UpdateOrderByProductID(product_id);
    }
}